﻿
# 本cmake文件，供三方引入CGraph引用，用于屏蔽系统和C++版本的区别

if(APPLE)
    # 非mac平台，暂时不支持自动生成session信息
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -finline-functions -Wno-deprecated-declarations -Wno-c++17-extensions")
    add_definitions(-D_GENERATE_SESSION_)
    add_definitions(-D_ENABLE_LIKELY_)
elseif(UNIX)
    # linux平台，加入多线程内容
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -pthread -Wno-format-overflow")
    add_definitions(-D_ENABLE_LIKELY_)
elseif(WIN32)
    if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
        message("Clang")
    elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
        message("GNU")
    elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
        message("Intel")
    elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
        message("MSVC")
        # windows平台，加入utf-8设置。否则无法通过编译
        add_definitions(/utf-8)

        # 禁止两处warning级别提示
        add_compile_options(/wd4996)
        add_compile_options(/wd4267)
    endif()
endif()

#option(ENABLE_PRECOMPILED_HEADERS "ENABLE_PRECOMPILED_HEADERS" OFF)

#set(COMPILER_FLAGS)
#set(COMPILER_FLAGS_DEBUG)
#set(COMPILER_FLAGS_RELEASE)

# Define useful variables to handle Compiler/IDE differences:
if (MSVC)
    # Flags for linking with multithread static C++ runtime
    set(CMAKE_C_FLAGS_RELEASE   "${CMAKE_C_FLAGS_RELEASE} /MT")
    set(CMAKE_C_FLAGS_DEBUG     "${CMAKE_C_FLAGS_DEBUG} /MTd")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
    set(CMAKE_CXX_FLAGS_DEBUG   "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
else (MSVC)
    if (CMAKE_COMPILER_IS_GNUCXX)
        # GCC flags
        if (MINGW)
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all -Wall -Wextra -pedantic -Wformat-security -Winit-self -Wswitch-enum -Wfloat-equal -Wshadow -Wcast-qual -Wconversion -Wlogical-op -Winline")
        else (MINGW)
            add_definitions(-rdynamic ${SHARED_PTR_GCC_CFLAGS})
        endif (MINGW)
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
        # Clang flags
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all -Wall -Wextra -pedantic -Wformat-security -Winit-self -Wswitch-enum -Wfloat-equal -Wshadow -Wcast-qual -Wconversion -Winline")
    endif (CMAKE_COMPILER_IS_GNUCXX)
endif (MSVC)


#if (WIN32)
#    set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS}   /MP /wd4200")
#    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /wd4200 /std:c++14")
#else ()
#    set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS}   -Wall -fPIC -pipe -std=gnu90")
#    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIC -pipe -std=c++11 -fno-exceptions -Wno-invalid-offsetof")
#endif ()

#Debug（调试）：此build type通常用于开发和调试阶段。它包含了调试信息，不进行任何优化，以便在调试时能够更轻松地追踪代码。

#Release（发布）：Release build type通常用于生产环境中。它会启用各种优化选项，以提高代码的执行速度和效率。

#RelWithDebInfo（发布带调试信息）：这种build type结合了Release和Debug的特性，旨在提供一种较好的优化效果同时保留调试信息，以便在需要时进行调试。

#MinSizeRel（最小体积发布）：MinSizeRel build type旨在最小化可执行文件的大小，通常会启用一些针对代码大小的优化。


if(CMAKE_BUILD_TYPE MATCHES "Release")
    set(CMAKE_BUILD_POSTFIX ${CMAKE_RELEASE_POSTFIX})
elseif(CMAKE_BUILD_TYPE MATCHES "Debug")
    set(CMAKE_BUILD_POSTFIX ${CMAKE_DEBUG_POSTFIX})
elseif(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
    set(CMAKE_BUILD_POSTFIX ${CMAKE_RELWITHDEBINFO_POSTFIX})
elseif(CMAKE_BUILD_TYPE MATCHES "MinSizeRel")
    set(CMAKE_BUILD_POSTFIX ${CMAKE_MINSIZEREL_POSTFIX})
else()
    set(CMAKE_BUILD_POSTFIX ${CMAKE_DEBUG_POSTFIX})
endif()
